import "./app.css";
import requirejs from "./utils/initRequireJs";
import * as appCode from "./appCode.js"

type FrontendCode = {
  id: string;
  type: string;
  props: {
    style?: {
      top: number;
      left: number;
      width: number;
      height: number;
      backgroundColor: string;
    };
  };
  moduleProps?: undefined;
  styleProps?: undefined;
  pageProps?: {
    path: string;
  };
  define?: (e: any) => void;
};
interface AppCode {
  frontendCode: FrontendCode[];
  frontendConfig: any;
  npmImports: {
    moduleName: string;
    define: (define: any) => void;
  }[];
  AppNodeId: string;
  AppId: string;
}

// const appCode = require("./appCode") as AppCode;

// console.log(appCode);
const { frontendCode, npmImports, AppNodeId } = appCode as AppCode;
npmImports.map((code) => {
  // console.log(code)
  if (code.define) {
    requirejs.execDefine(code.define, code.moduleName);
  }
});
// console.log("dfwfwfwef",requirejs.requireModule("dayjs"));
frontendCode.map((code) => {
  if (code.define) {
    requirejs.execDefine(code.define, code.id);
  }
});

const MainApp = requirejs.requireModule(AppNodeId);
export default MainApp?.default;

// export default function App({children}) {
//   return children;
// }
